package com.ccc.boot.monitor.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ccc.boot.constant.CommonConstant;
import com.ccc.boot.entity.SysUserOnline;
import com.ccc.boot.monitor.service.SysUserOnlineService;
import com.ccc.boot.pojo.Query;
import com.ccc.boot.response.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 在线登录用户管理
 *
 * @author superC
 * @version 2.0.0
 * @date 2022/4/24
 */

@RestController
@RequestMapping(CommonConstant.MONITOR_URI_PREFIX + "/online")
public class OnlineController {

    @Autowired
    private SysUserOnlineService onlineService;

    /**
     * 查询分页列表
     */
    @GetMapping("/pageList")
    @PreAuthorize("hasAuthority('ADMIN')")
    public ResponseResult pageList(@RequestParam Map<String, Object> params) {
        Query query = new Query(params);
        IPage<SysUserOnline> list = onlineService.page(query);
        return ResponseResult.success("查询成功", list);
    }


    /**
     * 强退
     *
     * @date 2022/5/1 20:15
     * @param data
     * @return {@link ResponseResult}
     * @author superC
     */

    @PostMapping("/forcedReturn")
    @PreAuthorize("hasAuthority('ADMIN')")
    public ResponseResult forcedReturn(@RequestBody SysUserOnline data) {
        onlineService.forcedReturn(data.getId());
        return ResponseResult.success("强退成功");
    }

}
